package domain;

import java.net.*;
import static java.lang.System.out;

public class Server
{
	

	static ServerSocket listenerSocket;
	static Socket clientSocket;
	private static final int listeningPorted = 2012;
	private static final int maxconnections = 20;
	
	private ContactList contactList;
	private Contact contact;
  
	// private
	// String remoteHostName;
   
	public void InitServer()
	{
		try
		{
			listenerSocket = new ServerSocket(listeningPorted, maxconnections);

		}
		catch (Exception ex)
		{
			out.print("can't listen on port: " + listeningPorted + ","
					+ ex.getLocalizedMessage());
			System.exit(0);
		}
		out.println("Server listening on port: " + listeningPorted);

		try
		{
			while (true)
			{

				clientSocket = new Socket();

				clientSocket = listenerSocket.accept();
				new ConnectionHandler(clientSocket);
				contact = new Contact(clientSocket);
				
				contactList.addContact(contact);			
				

			}

		}
		catch (Exception ex)
		{
			out.println("\nError: " + ex.getLocalizedMessage());
		}

	}
}
